"use strict";

// @ts-check
const serializer = require("dom-serializer");
const domHandler = require("domhandler");
const domUtils = require("domutils");
const hp2 = require("htmlparser2");

/**
 * @param {string} data
 * @param {hp2.Options} options
 * @returns {domHandler.Document}
 */
function parseDocument(data, options) {
  const handler = new hp2.DomHandler(undefined, options);
  new hp2.Parser(handler, options).end(data);
  return handler.root;
}

const dom = parseDocument(
  `<div id="app" ng-app="root" ng-strict-di="true" ng-csp="no-unsafe-eval">
      11<app-root>11</app-root>
    </div>`,
  {},
);

/**
 * @param {domHandler.ChildNode} node
 */
function domWalker(node) {
  if (node.type === hp2.ElementType.ElementType.Text) {
    // contentArr.push(node.data)
    // node.data ;
    // node.attribs["data-inspect"] = "nhp";
    node.data = node.data.trim();
  } else if (
    node.type === hp2.ElementType.ElementType.Tag &&
    node.childNodes.length
  ) {
    for (const n of node.childNodes) {
      domWalker(n);
    }
  }
}
for (const n of dom.childNodes) {
  domWalker(n);
}
// 没有loc信息
console.log(serializer.render(dom));
